namespace DotNetNuke.Modules.Admin.ResourceInstaller
{
    using DotNetNuke.Entities.Modules;
    using DotNetNuke.Framework;
    using DotNetNuke.Services.Exceptions;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Runtime.CompilerServices;

    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The PaDnnInstaller_V3 extends PaDnnInstallerBase to support V3 Modules
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// [cnurse]	04/21/2005  documented
    /// </history>
    /// -----------------------------------------------------------------------------
    public class PaDnnInstaller_V3 : PaDnnInstallerBase
    {
        public PaDnnInstaller_V3(PaInstallInfo InstallerInfo) : base(InstallerInfo)
        {
        }

        protected override DesktopModuleInfo GetDesktopModule(PaFolder Folder)
        {
            DesktopModuleController objDesktopModules = new DesktopModuleController();
            return objDesktopModules.GetDesktopModuleByModuleName(Folder.ModuleName);
        }

        protected override DesktopModuleInfo GetDesktopModuleSettings(DesktopModuleInfo objDesktopModule, PaFolder Folder)
        {
            objDesktopModule = base.GetDesktopModuleSettings(objDesktopModule, Folder);
            objDesktopModule.BusinessControllerClass = Folder.BusinessControllerClass;
            objDesktopModule.IsSearchable = false;
            objDesktopModule.IsPortable = false;
            try
            {
                if (objDesktopModule.BusinessControllerClass == "")
                {
                    return objDesktopModule;
                }
                object objController = RuntimeHelpers.GetObjectValue(Reflection.CreateObject(objDesktopModule.BusinessControllerClass, objDesktopModule.BusinessControllerClass));
                if (objController is ISearchable)
                {
                    objDesktopModule.IsSearchable = true;
                }
                if (objController is IPortable)
                {
                    objDesktopModule.IsPortable = true;
                }
            }
            catch (Exception exception1)
            {
                
                
            }
            return objDesktopModule;
        }

        protected override string UpgradeModule(DesktopModuleInfo ModuleInfo)
        {
            string Results = "";
            if (ModuleInfo.BusinessControllerClass != "")
            {
                try
                {
                    IEnumerator refObjectHelperL0=null;
                    object objObject = RuntimeHelpers.GetObjectValue(Reflection.CreateObject(ModuleInfo.BusinessControllerClass, ModuleInfo.BusinessControllerClass));
                    if (!(objObject is IUpgradeable))
                    {
                        return Results;
                    }
                    try
                    {
                        refObjectHelperL0 = this.UpgradeVersions.GetEnumerator();
                        while (refObjectHelperL0.MoveNext())
                        {
                            string Version = Conversions.ToString(refObjectHelperL0.Current);
                            Results = Results + ((IUpgradeable) objObject).UpgradeModule(Version);
                        }
                    }
                    finally
                    {
                        if (refObjectHelperL0 is IDisposable)
                        {
                            (refObjectHelperL0 as IDisposable).Dispose();
                        }
                    }
                }
                catch (Exception exception1)
                {
                    
                    Exception ex = exception1;
                    DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                    
                }
            }
            return Results;
        }
    }
}

